package com.jobjoin.jobjoin.common.util;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author WinsomeCheong
 * @date 2021-04-19 9:50
 **/
//定义具体的数据返回格式
@Data()
public class R {
        private Boolean success;

        private Integer code;

        private String msg;

        private Map<String,Object> data=new HashMap<>();

        private R(){}

        public static R ok(){
            R r = new R();
            r.setSuccess(true);
            r.setCode(ResultCode.SUCCESS);
            r.setMsg("操作成功");
            return r;
        }
        public static R error(){
            R r = new R();
            r.setSuccess(false);
            r.setCode(ResultCode.ERROR);
            r.setMsg("操作失败");
            return r;
        }
        public R success(Boolean success){
            this.setSuccess(success);
            return this;
        }
        public R code(Integer code){
            this.setCode(code);
            return this;
        }
        public R msg(String msg){
            this.setMsg(msg);
            return this;
        }
        public R data(String key,Object value){
            this.data.put(key,value);
            return this;
        }
}
